package cn.shengongying.api.dto;

import cn.shengongying.enums.ResponseCodeEnum;
import cn.shengongying.exception.ParamException;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotEmpty;

/**
 * author: RXK
 * date: 2022/1/6 星期四
 * desc:
 */
@Getter
@Setter
@ApiModel(value = "登录入参")
public class LogInDTO {

    @ApiModelProperty(value ="登录方式(0:手机号码一键登录;1:手机号码+验证码)")
    private Integer type;

    @ApiModelProperty(value = "手机号码")
    private String phone;

    @ApiModelProperty(value = "一键登录传token,验证码登录传code")
    @NotEmpty(message = "缺少参数")
    private String code;

    @ApiModelProperty(value = "gyuid(一键登录必传)")
    private String gyuid;

    public void checkParam() {
        switch (type) {
            case 0:
                if (StringUtils.isAnyEmpty(gyuid)) {
                    throw new ParamException(ResponseCodeEnum.param_exception);
                }
                break;
            case 1:
                if (StringUtils.isAnyEmpty(code,phone)) {
                    throw new ParamException(ResponseCodeEnum.param_exception);
                }
                break;
            default:
                throw new ParamException(ResponseCodeEnum.param_exception);
        }
    }
}
